# 使用官方jupyter镜像
FROM jupyter/base-notebook

# 切换到root用户执行源替换
USER root

# 替换为阿里云源（包含debian和security源）
RUN sed -i 's|http://deb.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list && \
    sed -i 's|http://security.debian.org|https://mirrors.aliyun.com/debian-security|g' /etc/apt/sources.list && \
    apt-get update && apt-get clean

# 切换回原用户
USER ${NB_UID}

# 配置pip国内源
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ || \
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

# 添加conda国内源（清华源）
RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ && \
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/ && \
    conda config --set show_channel_urls yes

# 使用变量替代硬编码路径
COPY . /work
WORKDIR /work
RUN pip install --no-cache-dir -r requirements.txt && \
    conda update backports -y

# 制作镜像：docker build -t jupyter-test:shenll .
# 运行命令：docker run --name my-jupyter -p 外部端口:8080 -v 宿主目录:容器目录 your_image_name
# 例如：docker run --name my-jupyter -p 9999:8080 -v {pwd: tmp/db}:/work/tmp -v {pwd: .}:/work jupyter-test:shenll
CMD ["jupyter", "notebook", "--port", "8080"]